package com.hjm.ui.home;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hjm.ui.R;
import com.hjm.ui.home.adapter.HomeNavAdapter;

import java.util.List;

public class HomeNav extends LinearLayout {
    private List<? extends HomeNavAdapter.Nav> navs;
    private RecyclerView homeNavRecyclerView;
    private HomeNavAdapter homeNavAdapter;
    public HomeNav(Context context) {
        super(context);
        init();
    }

    public HomeNav(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public HomeNav(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    void init(){
        LayoutInflater.from(getContext()).inflate(R.layout.layout_home_nav, this, true);
        homeNavRecyclerView = findViewById(R.id.recycler_view_home_nav);

    }
    public <T extends HomeNavAdapter.Nav> void setData(List<T> navs, HomeNavAdapter.OnclickListener onClickListener){
        this.navs = navs;
        homeNavRecyclerView.setLayoutManager(new LinearLayoutManager(this.getContext(), LinearLayoutManager.HORIZONTAL, false));
        homeNavAdapter = new HomeNavAdapter(navs, onClickListener,this.getContext());
        homeNavRecyclerView.setAdapter(homeNavAdapter);
    }
}
